package com.san.hkhospital.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.entity.Examine;
import com.san.hkhospital.entity.SurDo;
import com.san.hkhospital.service.SurDoService;
import com.san.hkhospital.service.impl.SurDoServiceImpl;
import com.san.hkhospital.vo.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (sur_do)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/sur_do")
public class SurDoController {
/**
* 服务对象
*/
@Resource
private SurDoServiceImpl surDoServiceImpl;
@Resource
private SurDoService surDoService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping(value = "/{id}")
public ResultVO selectOne(@PathVariable Integer id) {
    SurDo surDo =surDoService.find(id);
    if(surDo!=null){
        return ResultVO.success("一个手术单查找成功！",surDo);
    }else{
        return ResultVO.failed("一个手术单查找失败！");
    }
}
    @GetMapping
    public ResultVO surdoList(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<surdoTableVO> surdoList = surDoService.findAll();
        PageInfo<surdoTableVO> pageInfo =new PageInfo<surdoTableVO>(surdoList);
        return ResultVO.success("所有手术单查询成功！",pageInfo);
    }
    @PostMapping
    public ResultVO add(@RequestBody SurDo surDo){
        boolean flag =  surDoService.add(surDo);
        if(flag){
            return ResultVO.success("添加手术单成功！");
        }else{
            return ResultVO.failed("添加手术单失败！");
        }
    }
    @PutMapping()
    public ResultVO update(@RequestBody SurDo surDo){
        boolean flag = surDoService.update(surDo);
        if(flag){
            return ResultVO.success("手术单修改成功！");
        }else{
            return ResultVO.failed("手术单修改失败！");
        }
    }
    @RequestMapping("Search")
    public ResultVO Search(@RequestBody Search2 search2, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<surdoTableVO> examineTableVOList = surDoService.search(search2);
        PageInfo<surdoTableVO> pageInfo =new PageInfo<>(examineTableVOList);
        return ResultVO.success("搜索查询成功！",pageInfo);
    }
    @RequestMapping("ShoushuKai")
    public ResultVO  ShoushuKai(@RequestParam Integer sdId){
        boolean flag = surDoService.shoushuStart(sdId);
        if(flag){
            return ResultVO.success("手术开始时间开始！");
        }else{
            return ResultVO.failed("手术开始时间未开始！");
        }
    }
    @RequestMapping("ShoushuJie")
    public ResultVO  ShoushuJie(@RequestParam Integer sdId){
        boolean flag = surDoService.shoushuEnd(sdId);
        if(flag){
            return ResultVO.success("手术结束时间结束！");
        }else{
            return ResultVO.failed("手术结束时间未结束！");
        }
    }
}
